/**
 * 
 */
package idv.takeshi.software.productline.bookstore.application.service.dto;

import idv.takeshi.software.productline.bookstore.domain.model.order.Order;
import idv.takeshi.software.productline.bookstore.domain.model.order.PostalOrder;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.apache.commons.lang.Validate;

/**
 * A DTO for maintaining postal-
 * @author takeshi
 *
 */
public class PostalOrderPaymentDto extends PaymentDto {
	
	@Pattern(regexp = ".+")
	@NotNull
	private String receiverName;
	
	@Pattern(regexp = ".+")
	@NotNull
	private String payerName;
	
	@Pattern(regexp = ".+")
	@NotNull
	private String address;
	
	@Pattern(regexp = "\\d+")
	@NotNull
	private String phoneNumber;
	
	@Pattern(regexp = "\\d{16,16}+")
	@NotNull
	private String depositAccountNumber;
	
	
	@Pattern(regexp = "\\d{3,3}+")
	@NotNull
	private String depositBankId;
	
	/**
	 * Default constructor
	 */
	public PostalOrderPaymentDto() {
		super();
	}

	/**
	 * Initial this DTO by given postal order model.
	 * @param postalOrder
	 */
	public PostalOrderPaymentDto(Order order) {
		super(order);
		PostalOrder postalOrder = (PostalOrder) order.getPayment();
		this.receiverName = postalOrder.getReceiverName();
		this.payerName = postalOrder.getPayerName();
		this.address = postalOrder.getAddress();
		this.phoneNumber = postalOrder.getPhoneNumber();
		this.depositAccountNumber = postalOrder.getDepositForAccountNumber();
		this.depositBankId = postalOrder.getDepositForBankId();
	}

	/**
	 * @return the receiverName
	 */
	public String getReceiverName() {
		return receiverName;
	}

	/**
	 * @param receiverName the receiverName to set
	 */
	public void setReceiverName(String receiverName) {
		this.receiverName = receiverName;
	}

	/**
	 * @return the payerName
	 */
	public String getPayerName() {
		return payerName;
	}

	/**
	 * @param payerName the payerName to set
	 */
	public void setPayerName(String payerName) {
		this.payerName = payerName;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the phoneNumber
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param phoneNumber the phoneNumber to set
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	/**
	 * @return the depositAccountNumber
	 */
	public String getDepositAccountNumber() {
		return depositAccountNumber;
	}

	/**
	 * @param depositAccountNumber the depositAccountNumber to set
	 */
	public void setDepositAccountNumber(String depositAccountNumber) {
		this.depositAccountNumber = depositAccountNumber;
	}

	/**
	 * @return the depositBankId
	 */
	public String getDepositBankId() {
		return depositBankId;
	}

	/**
	 * @param depositBankId the depositBankId to set
	 */
	public void setDepositBankId(String depositBankId) {
		this.depositBankId = depositBankId;
	}
	
	
	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.application.service.dto.PaymentDto#loadModel(idv.takeshi.software.productline.bookstore.domain.model.order.Order)
	 */
	public void loadModel(Order order){
		super.loadModel(order);
		
		PostalOrder postalOrder = (PostalOrder) order.getPayment();
		postalOrder.setReceiverName(receiverName);
		postalOrder.setPayerName(payerName);
		postalOrder.setAddress(address);
		postalOrder.setPhoneNumber(phoneNumber);
		postalOrder.setDepositForAccountNumber(depositAccountNumber);
		postalOrder.setDepositForBankId(depositBankId);
	}
}
